﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModuleITDesk.DAL.Model;
namespace ModuleITDesk.DAL
{
    public class DALCheckedLogin
    {
        private ModuleITDeskEntities contextDB;
        public DALCheckedLogin()
        {
            contextDB = new ModuleITDeskEntities();
        }
        public CheckLoginDto CheckedLogin(string username, string password)
        {
            CheckLoginDto checkedLogin = new CheckLoginDto();
            try
            {
                var objUser = contextDB.Users.Where(attr => attr.UserName == username && attr.Password == password).First();                
                if (objUser != null)
                {
                    checkedLogin.IsSuccess = true;
                    checkedLogin.UserId = objUser.UserID;
                    checkedLogin.Username = objUser.UserName;
                    checkedLogin.Password = objUser.Password;
                    checkedLogin.FirstName = objUser.FirstName;
                    checkedLogin.LastName = objUser.LastName;
                    checkedLogin.Email = objUser.Email;
                    checkedLogin.WhichOne = objUser.WhichOne;
                    checkedLogin.Permission = objUser.Permission;
                    checkedLogin.Message = "Login is successful";
                    return checkedLogin;
                }                
                else
                { 
                    checkedLogin.IsSuccess = false;
                    return checkedLogin;
                }
            }
            catch (Exception exx)
            {
                checkedLogin.IsSuccess = false;
                checkedLogin.Message = "Username or Password is incorrect";
                return checkedLogin;
            }   
        }
    }
}
